package com.pj.wisdomlogistics.mvp.presenter;


import com.pj.wisdomlogistics.entity.CarDetailInfo;
import com.pj.wisdomlogistics.mvp.contract.CarDetailContract;
import com.pj.wisdomlogistics.mvp.frame.ActivityPresenter;
import com.pj.wisdomlogistics.mvp.model.CarDetailModel;
import com.pj.wisdomlogistics.rx.FilterSubscriber;

import java.io.File;


public class CarDetailPresenter extends ActivityPresenter<CarDetailModel,CarDetailContract.View> implements CarDetailContract.Presenter{
    public static final String TAG = "CarDetailPresenter";

    @Override
    public void findCarApplyDetail(int carApplyID) {
        addSubscription(getModel().findCarApplyDetail(carApplyID), new FilterSubscriber<CarDetailInfo>() {
            @Override
            public void onNext(CarDetailInfo mInfo) {
                getView().onSuccess(mInfo);
            }

            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

        });
    }

    @Override
    public void carApplySign(int carApplyID, String signUID, File sign, int state, String comment) {
        addSubscription(getModel().carApplySign(carApplyID, signUID, sign, state, comment), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().onSignSuccess();
            }
        });
    }

    @Override
    public void carApplyComment(String userID, int carApplyID, String comment, int state) {
        addSubscription(getModel().carApplyComment(userID, carApplyID, comment, state), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().onCheckSuccess();
            }
        });
    }

    @Override
    public void carApplyAllot(String userID, String carApplyID, String state, String driverName,
                              String driverTel, String carModel, String carNum, String driverID, String carID , String comment) {
        addSubscription(getModel().carApplyAllot(userID, carApplyID, state, driverName, driverTel, carModel, carNum, driverID, carID , comment), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().onSendSuccess();
            }
        });
    }

    @Override
    public void carApplyAssess(String assess, String carApplyID, int levels) {
        addSubscription(getModel().carApplyAssess(assess, carApplyID, levels), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().onPjSuccess();
            }
        });
    }

    @Override
    public void carApplyFinish(String userID, int carApplyID , String beforeMile , String afterMile) {
        addSubscription(getModel().carApplyFinish(userID, carApplyID , beforeMile , afterMile), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().onFinishSuccess();
            }
        });
    }

    @Override
    public void cancelCar(int carApplyID) {
        addSubscription(getModel().cancelCar(carApplyID), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().onUndoSuccess();
            }
        });
    }

}
